<template>
  <div id="add-picture-batch-page">
    <a-form layout="vertical" :model="formData" name="formData" @finish="handSubmit">
      <a-form-item name="searchText" label="关键词">
        <a-input v-model:value="formData.searchText" placeholder="请输入关键词" />
      </a-form-item>
      <a-form-item name="instruction" label="数量">
        <a-input-number v-model:value="formData.count" min="1" max="20" style="min-width: 200px">
        </a-input-number>
      </a-form-item>
      <a-form-item name="namePrefix" label="名称前缀">
        <a-input v-model:value="formData.namePrefix" placeholder="请输入名称前缀，会自动添加序号" />
      </a-form-item>
      <a-form-item>
        <a-button type="primary" html-type="submit" style="width: 100%" :loading="loading"
          >提交</a-button
        >
      </a-form-item>
    </a-form>
  </div>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
import { uploadPictureByBatchUsingPost } from '@/api/pictureController'
import { useRouter } from 'vue-router'

const picture = ref<API.PictureVO>()

const router = useRouter()
const formData = reactive<API.PictureUploadByBatchRequest>({
  count: 10,
})
const loading = ref(false)
/**
 * 提交表单
 * @param values
 */
const handSubmit = async (values: any) => {
  loading.value = true
  const res = await uploadPictureByBatchUsingPost({
    ...formData,
  })
  if (res.data.code === 0 && res.data.data) {
    message.success(`图片创建成功，共${ res.data.data}条'`)
    router.push({
      path: `/`,
    })
  } else {
    message.error('图片创建失败' + res.data.message)
  }
  loading.value = false
  return
}
</script>
<style scoped>
#add-picture-batch-page {
  max-width: 720px;
  margin: 0 auto;
}
</style>
